package com.streetsmart;

/**
 * 
 * @author bhavani sudha
 *
 */
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

/**
 * 
 * records the current location periodically, which is usually updated by a
 * broadcast from lacation service. Records the location updates into the table
 * "RecentLocations"
 * 
 */
public class LocationReceiver extends BroadcastReceiver {

	Context context;

	@Override
	public void onReceive(Context context, Intent calledIntent) {
		//if (calledIntent.getAction().equals("android.intent.action.LOCATION")) {
			Log.d("LOC_RECEIVER", "Location RECEIVED!");
			this.context = context;
			Bundle b = calledIntent.getExtras();
			double latitude = b.getDouble("latitude");
			double longitude = b.getDouble("longitude");

			updateRemote(latitude, longitude);
		//}

	}

	private void updateRemote(final double latitude, final double longitude) {
		DBManager dbmanager = new DBManager(context);
		dbmanager.saveRecentLocation(latitude, longitude);
		dbmanager.close();
	}
}
